package com.xixibaby.pay.wechat;

import com.egzosn.pay.ali.api.AliPayService;
import com.egzosn.pay.ali.bean.AliTransactionType;
import com.egzosn.pay.common.api.PayConfigStorage;
import com.egzosn.pay.common.bean.CertStoreType;
import com.egzosn.pay.common.bean.PayOrder;
import com.egzosn.pay.common.bean.TransactionType;
import com.egzosn.pay.common.http.HttpConfigStorage;
import com.egzosn.pay.wx.api.WxPayService;
import com.egzosn.pay.wx.bean.WxTransactionType;
import com.xixibaby.core.Prototypes;
import com.xixibaby.pay.AbstractPay;
import com.xixibaby.pay.Pay;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author tooomj
 */
@Component
@Prototypes(key = Pay.class,value = 2)
public class WechatPay extends AbstractPay<WxPayService> {

    @Override
    protected TransactionType getAppTransType() {
        return WxTransactionType.APP;
    }

    @Override
    protected void overConfig(PayConfigStorage payConfigStorage) {
        if(payConfigStorage instanceof WechatPayConfig){
            WechatPayConfig config = (WechatPayConfig) payConfigStorage;
            config.setAppid(config.getWappid());
            HttpConfigStorage httpConfigStorage = new HttpConfigStorage();
            //ssl 退款证书相关 不使用可注释
            httpConfigStorage.setKeystore(config.getKeystore());
            httpConfigStorage.setStorePassword(config.getKeystorePass());
            //设置ssl证书对应的存储方式，这里默认为文件地址
            httpConfigStorage.setCertStoreType(CertStoreType.PATH);
            //最大连接数
            httpConfigStorage.setMaxTotal(20);
            //默认的每个路由的最大连接数
            httpConfigStorage.setDefaultMaxPerRoute(10);
            //--- 退费 end
            this.payService.setRequestTemplateConfigStorage(httpConfigStorage);
            this.payService.setPayConfigStorage(config);
        }
    }
}
